<template>
  <div class="d_mainFlex">
    <div class="d_treeBox">
      <div class="maerMange">
        <div class="title">
          <h3>物料管理</h3>
        </div>
        <div class="treeList">
          <ul>
            <li :class="isAllMateriel ? 'on' : ''" @click="getllMateriels">
              <i class="iconfont warIco" />
              <p>全部物料</p>
            </li>
          </ul>
        </div>
        <div class="title">
          <h3>基础数据</h3>
          <span
            class="c_3F61F1 pointer"
            v-permission="'MenuCode5-10-1-6'"
            @click="addMaterirlClass = true"
            ><i class="el-icon-plus" />新增分组</span
          >
        </div>
        <div class="d_nrBox">
          <div class="treeList">
            <ul>
              <li
                v-for="(item, index) in allMaterielClass"
                :key="item.groupID"
                :class="classIndex === index ? 'on' : ''"
              >
                <div
                  class="flexLc flex_1"
                  @click="changeMaterClass(item, index)"
                >
                  <i class="iconfont folderIco" />
                  <p>{{ item.groupName }}({{ item.speciesQuantity }})</p>
                </div>
                <div class="kuOP">
                  <el-popover
                    :ref="`popover-${index}`"
                    placement="bottom"
                    popper-class="areasPopover"
                    trigger="click"
                  >
                    <div class="areasOp">
                      <ul>
                        <li
                          v-permission="'MenuCode5-10-1-7'"
                          @click="updateMaClass(item)"
                        >
                          修改
                        </li>
                        <li
                          v-permission="'MenuCode5-10-1-8'"
                          @click="deleteMaterielClass(item)"
                        >
                          删除
                        </li>
                      </ul>
                    </div>
                    <span slot="reference" class="el-icon-more c_3F61F1" />
                  </el-popover>
                </div>
              </li>
            </ul>
          </div>
          <div v-if="allMaterielClass.length == 0" class="pl16 pr16">
            <el-skeleton :rows="10" animated />
          </div>
        </div>
        <!-- 物料所有分组       -->
      </div>
    </div>
    <div class="case">
      <div class="title">
        <h3>{{ subTitle }}({{ total || 0 }})</h3>
      </div>
      <na-table
        :datas.sync="tableData"
        :searchObj.sync="search"
        @updateDatas="getAllMaterils"
        @newAdd="newAddClick"
        @checkboxChange="handleIsShowDisabled"
        @change="handleSearch"
      >
      </na-table>
    </div>
    <!-- 新建物料   -->
    <el-dialog
      :title="titleName+'物料'"
      :visible.sync="isAddMaterriel"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="30%"
      @close="closeDialog"
    >
      <div class="dialogDody">
        <div class="addWuliaoBox">
          <el-form
            ref="materForm"
            :model="materForm"
            :disabled="isDisable"
            :rules="materFormRules"
            label-width="120px"
            class="dialogForm dialogInlineForm"
          >
            <el-form-item label="物料编号" prop="goodsCode">
              <el-input
                v-model="materForm.goodsCode"
                placeholder="系统自动生成"
                disabled
                size="mini"
              />
            </el-form-item>
            <el-form-item label="物料类型" prop="categoryCode">
              <el-select
                        filterable
                v-model="materForm.categoryCode"
                placeholder="物料类型"
                size="mini"
                :disabled="ops == 'model'|| type== 'confirm'"
                @change="$forceUpdate()"
              >
                <el-option
                  v-for="item in allMaterielTypes"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="物料分组" prop="groupCode">
              <el-select
                        filterable
                v-model="materForm.groupCode"
                placeholder="物料分组"
                :disabled="ops == 'model'|| type== 'confirm'"
                @change="$forceUpdate()"
                size="mini"
              >
                <el-option
                  v-for="item in allMaterielClass"
                  :key="item.groupID"
                  :label="item.groupName"
                  :value="item.groupCode"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="物料名称" prop="goodsName">
              <el-input
                v-model="materForm.goodsName"
                :disabled="ops == 'model'"
                placeholder="请输入内容"
                size="mini"
              />
            </el-form-item>
            <el-form-item label="供应商" prop="supplierCode">
              <el-select
                        filterable
                v-model="materForm.supplierCode"
                @change="$forceUpdate()"
                placeholder="供应商"
                size="mini"
                :disabled="ops == 'model'|| type== 'confirm'"
                clearable
                filterable
              >
                <el-option
                  v-for="(item, index) in allSupliers"
                  :key="index"
                  :label="item.supplierName"
                  :value="item.supplierCode"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="规格型号" prop="specificationName">
              <el-input
                v-model="materForm.specificationName"
                placeholder="规格型号"
                :disabled="type== 'confirm'"
                size="mini"
                @input="$forceUpdate()"
                clearable
              />
            </el-form-item>
            <el-form-item label="使用单位" prop="goodsUnitCode">
              <el-select
                        filterable
                v-model="materForm.goodsUnitCode"
                placeholder="使用单位"
                :disabled="ops == 'model'||type== 'confirm'"
                size="mini"
              >
                <el-option
                  v-for="item in materielCompany"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="计价单位">
              <el-select
                        filterable
                v-model="materForm.priceUnitCode"
                placeholder="计价单位"
                :disabled="ops == 'model'||type== 'confirm'"
                size="mini"
              >
                <el-option
                  v-for="item in materielCompany"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="计价转换比例" prop="specificationJsValue">
              <el-input
                v-model="materForm.specificationJsValue"
                type="number"
                placeholder="计价转换比例"
                :disabled="type== 'confirm'"
                size="mini"
                clearable
              >
              </el-input>
            </el-form-item>
            <el-form-item label="采购单价">
              <el-input
                v-model="materForm.goodsPrice"
                disabled
                type="number"
                placeholder="请输入采购单价"
                size="mini"
                clearable
              />
            </el-form-item>
            <el-form-item label="快捷键">
              <el-input
                v-model="materForm.searchHotKeys"
                placeholder="快捷键"
                :disabled="type== 'confirm'"
                size="mini"
                clearable
              />
            </el-form-item>

            <el-form-item label="物料备注" class="inlineText mt5">
              <el-input
                v-model="materForm.stockGoodsDesc"
                type="textarea"
                :disabled="type== 'confirm'"
                placeholder="物料备注"
                size="mini"
                clearable
              />
            </el-form-item>
            <el-form-item label="作废原因" v-if="materForm.reason" class="inlineText mt5">
              <el-input
                v-model="materForm.reason"
                type="textarea"
                disabled
                placeholder="作废原因"
                size="mini"
                clearable
              />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isAddMaterriel = false">取 消</el-button>
        <!--  新建保存      -->
        <el-button
          v-if="ops === 'add' || ops === 'model'"
          v-loading="addMaterrielLoading"
          :disabled="addMaterrielLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveMater"
          >保存</el-button
        >
        <!--  修改保存      -->
        <el-button
          v-if="ops === 'modify'"
          v-loading="addMaterrielLoading"
          :disabled="addMaterrielLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveEditMater"
          >保存</el-button
        >
      </div>
    </el-dialog>
    <!-- 新建物料分组   -->
    <el-dialog
      title="新建物料分组"
      :visible.sync="addMaterirlClass"
      :close-on-click-modal="false"
      custom-class="comDialog"
      width="35%"
      @close="closeClassDialog"
    >
      <div class="dialogDody">
        <el-form
          ref="materClassForm"
          :model="materClassForm"
          :rules="materClassRules"
          label-width="80px"
          class="dialogForm"
        >
          <el-form-item label="分组名称" prop="groupName">
            <el-input
              v-model="materClassForm.groupName"
              placeholder="分组名称"
              size="mini"
              clearable
            />
          </el-form-item>
          <el-form-item label="排序" prop="groupName">
            <el-input
              v-model="materClassForm.groupSort"
              placeholder="分组名称"
              size="mini"
              clearable
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="addMaterirlClass = false"
          >取 消</el-button
        >
        <el-button
          v-loading="addMaterClassLoading"
          :disabled="addMaterClassLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveMaterClass"
          >保存</el-button
        >
      </div>
    </el-dialog>
    <!-- 编辑物料分组   -->
    <el-dialog
      title="编辑物料分组"
      :visible.sync="editMaterirlClass"
      :close-on-click-modal="false"
      custom-class="comDialog"
      width="35%"
      @close="closeClassDialog"
    >
      <div class="dialogDody">
        <el-form
          ref="editMaterClassForm"
          :model="materClassForm"
          :rules="materClassRules"
          label-width="80px"
          class="dialogForm"
        >
          <el-form-item label="分组名称" prop="groupName">
            <el-input
              v-model="materClassForm.groupName"
              placeholder="分组名称"
              size="mini"
              clearable
            />
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="editMaterirlClass = false"
          >取 消</el-button
        >
        <el-button
          v-loading="addMaterClassLoading"
          :disabled="addMaterClassLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveEditMaterClass"
          >保存
        </el-button>
      </span>
    </el-dialog>

    <!-- 作废原因   -->
    <el-dialog
      title="作废原因'"
      :visible.sync="reasonVisible"
      :close-on-click-modal="false"
      custom-class="comDialog"
      append-to-body
      width="30%"
      @close="closeCancelDialog"
    >
      <div class="dialogDody">
        <el-form
          ref="cancelForm"
          :model="cancelForm"
          :rules="viodRules"
          label-width="0px"
          class="dialogForm"
        >
          <el-form-item label="" prop="reason">
            <el-input
              v-model="cancelForm.reason"
              type="textarea"
              :autosize="{ minRows: 3 }"
              placeholder="请输入内容"
              size="mini"
              clearable
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="reasonVisible = false">取 消</el-button>
        <el-button
          :loading="addLableLoading"
          :disabled="addLableLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveReason"
          >保存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { arraySort } from "@/utils";
import naTable from "@/components/naTable";
import pinyin from "js-pinyin";
import { mapGetters } from "vuex";

export default {
  name: "Materiel",
  components: {
    naTable,
  },
  computed: {
    ...mapGetters(["name"]),
    getPriceUnitName() {
      const code = this.materForm.priceUnitCode;
      const arr = this.materielCompany ? this.materielCompany : [];
      const obj = arr.length > 0 ? arr.find((m) => m.code === code) : {};
      return (obj && obj.name) || "";
    },
  },
  data() {
    return {
      ops: "add", // 物料操作、新建，修改，查看
      specsOps: "add", // 规格型号操作
      specsIndex: null, // 规格型号编辑行的索引
      specsVisible: false, // 新建规格型号是否打开
      type:'',
      subTitle: "全部物料",
      tableHeight: null, // 表格最大高度
      addMaterirlClass: false, // 新建物料分组弹框是否打开
      editMaterirlClass: false, // 编辑物料分组弹框是否打开
      addMaterClassLoading: false, // 新建物料分组加载效果
      isSeeMaterriel: false, // 查看物料弹框是否打开
      addLableLoading: false,
      isAddMaterriel: false, // 新建物料弹框是否打开
      isDisable:false,
      title: "新建",
      addMaterrielLoading: false, // 新建物料保存加载
      isAllMateriel: true, // 全部物料
      classIndex: null, // 选中分组索引
      searchLoading: false, // 搜索加载效果
      allMaterirls: [], // 全部物料数据列表
      allMaterielClass: [], // 所有物料分组
      reasonVisible: false,
      allMaterielTypes: [], // 物料类型
      materielCompany: [], // 物料单位
      allSupliers: [], // 所有供应商列表
      expands: [], // 要展开的行，数值的元素是row的key值
      // 物料分组表单
      materClassForm: {
        groupName: "",
        groupSort: 1000,
      },
      backupsGroupCode: "",
      cancelForm: {
        specificationCode: "",
        type: "",
        state: "",
        reason: "",
      },
      viodRules: {
        reason: [
          {
            required: true,
            message: "请填写原因",
            trigger: ["change", "blur"],
          },
        ],
      },
      // 新建物料表单
      materForm: {
        groupCode: "",
        categoryCode: "",
        goodsCode: "",
        goodsName: "",
        goodsUnitCode: "",
        isPriceUnit: true,
        priceUnitCode: "",
        goodsDesc: "",
        stockGoodsCode: "",
        stockGoodsName: "",
        specificationCode: "",
        specificationJsValue: 1,
        supplierCode: "",
        warehouseCode: "",
        warehouseAreaCode: "",
        areaShelfCode: "",
        isOpenWarning: 0,
        warningAmount: 0,
        searchHotKeys: "",
        stockGoodsDesc: "",
        goodsPrice: 0,
      },
      storageLocations: [], // 库区库位
      // 物料搜索条件
      search: {
        pageIndex: 1,
        pageSize: 30,
        likeWords: "",
        groupCode: "",
        categoryCode: "",
        goodsCode: "",
        goodsUnitCode: "",
        isShowDisable: 0,
        state: -1,
      },
      total: 0, // 物料总条数
      rowID: "",
      tableHead: [], // 物料表格表头
      materClassRules: {
        groupName: [
          {
            required: true,
            message: "请输入分组名称",
            trigger: "blur",
          },
        ],
      },
      materFormRules: {
        goodsName: [
          {
            required: true,
            message: "请输入物料名称",
            trigger: "blur",
          },
        ],
        groupCode: [
          {
            required: true,
            message: "请选择物料分组",
            trigger: "change",
          },
        ],
        categoryCode: [
          {
            required: true,
            message: "请选择物料类型",
            trigger: "change",
          },
        ],
        goodsUnitCode: [
          {
            required: true,
            message: "请选择物料单位",
            trigger: "change",
          },
        ],
        supplierCode: [
          {
            required: true,
            message: "请选择物供应商",
            trigger: "change",
          },
        ],
        specificationName: [
          {
            required: true,
            message: "请输入规格型号",
            trigger: "blur",
          },
        ],
      },
      specsRules: {
        supplierObj: [
          {
            required: true,
            message: "请选择供应商",
            trigger: "change",
          },
        ],
        stockGoodsName: [
          {
            required: true,
            message: "请填写规格型号",
            trigger: "blur",
          },
        ],
        specificationJsValue: [
          {
            required: true,
            message: "请填写转换比例",
            trigger: "blur",
          },
        ],
      },

      tableData: {
        headId: "head", //表头列显隐组件所需ID-避免多个页面id重复问题
        tableId: "goodsID", //表格列表key,也就是一条数据的唯一标识
        senior: false, //高级搜索是否显示
        disableWord: "isDisable", //是否禁用显示的字段
        disableStatus: "启用", //判断未禁用的状态值
        voidWord: "isShowDisable",
        checkboxLabel: "显示禁用",
        refresh: true, //刷新按钮
        addPermission: "MenuCode5-10-1-1", //新建按钮权限
        statusList: [
          {
            label: "全部",
            value: -1,
          },
          {
            label: "待确认",
            value: 0,
          },
          {
            label: "已确认",
            value: 1,
          },
          {
            label: "已作废",
            value: 2,
          },
        ], //状态筛选条件列表
        statusWord: "state", //状态筛选的字段
        //表格按钮
        operationBtn: [
          {
            title: "添加规格型号",
            methodsName: "handleAddModel",
          },
          {
            title: "查看",
            methodsName: "seeMateriel",
          },
          {
            title: "修改",
            methodsName: "modifyMateriel",
            hideCondition:{//按钮显隐条件
              prop:'state',//控制显隐的状态字段
              show:[//有哪些状态可以使用-值必须跟状态的类型保持一致
                '待确认',
                '已确认'
              ],
              // except:'',//除了某个状态其他都可以使用
            },
          },
          {
            title: "禁用",
            methodsName: "setMateriel",
          },
          {
            title: "作废",
            methodsName: "handleViod",
            isShowCheckbox: true,
            hideCondition:{//按钮显隐条件
              prop:'state',//控制显隐的状态字段
              show:[//有哪些状态可以使用-值必须跟状态的类型保持一致
                '待确认',
              ],
              // except:'',//除了某个状态其他都可以使用
            },
          },
          {
            title: "确认",
            methodsName: "handleConfirm",
            hideCondition:{//按钮显隐条件
              prop:'state',//控制显隐的状态字段
              show:[//有哪些状态可以使用-值必须跟状态的类型保持一致
                '待确认',
              ],
              // except:'',//除了某个状态其他都可以使用
            },
          },
          // {
          //   title: "复制",
          //   methodsName: "handleCopy",
          // },
          // {
          //   title: "删除",
          //   methodsName: "deleteMar",
          // },
        ],
        //表格内容
        tbody: [],
        //表格表头
        thead: [],
      },
    };
  },
  computed:{
    titleName:function(){
      let title
      if(this.ops == 'add' || this.ops == 'model'){
        title = '新增'
      }else if(this.ops == 'modify'){
        title = '修改'
      }else{
        title = '查看'
      }
      return title
    }
  },
  created() {
    // 所有物料列表数据
    this.getAllMaterils();
    // 物料表格得表头
    this.getTableHead();
    // 获取所有物料分组
    this.getMaterielClass();
    // 物料类型
    this.getMarTypes();
    // 物料单位
    this.getMarCompany();
    // 供应商
    this.getSupplier();
  },
  mounted() {},
  methods: {
    getRowKeys(row) {
      return row.goodsID;
    },

    // 新建物料点击事件
    newAddClick() {
      this.ops = "add";
      this.type = ''
      this.isDisable = false
      this.materForm.groupCode = this.backupsGroupCode;
      this.isAddMaterriel = true;
    },
    // 新建物料保存
    saveMater() {
      const parmas = this.materForm;
      this.$refs.materForm.validate((valid) => {
        if (valid) {
          if(this.ops == 'add'){
            this.addMaterrielLoading = true;
            this.$api.mater
              .getAddGoods(parmas)
              .then(() => {
                this.isAddMaterriel = false;
                this.addMaterrielLoading = false;
                this.getAllMaterils();
                // 获取所有物料分组
                this.getMaterielClass();
                this.$message({
                  message: "保存成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addMaterrielLoading = false;
              });
          }else if(this.ops == 'model'){
            this.materForm.remark = this.materForm.stockGoodsDesc
            this.addMaterrielLoading = true;
            this.$api.mater
              .AddSpecification(parmas)
              .then(() => {
                this.isAddMaterriel = false;
                this.addMaterrielLoading = false;
                this.getAllMaterils();
                // 获取所有物料分组
                this.getMaterielClass();
                this.$message({
                  message: "保存成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addMaterrielLoading = false;
              });
          }
        }
      });
    },

    //作废
    handleViod(data) {
      this.cancelForm.specificationCode = data.specificationCode;
      this.cancelForm.type = 1
      this.cancelForm.state = 2
      this.reasonVisible = true;
    },

    //确认
    handleConfirm(data){
      this.$confirm("是否确定该数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.cancelForm.specificationCode = data.specificationCode;
        this.cancelForm.type = 1
        this.cancelForm.state = 1
        this.saveOrderState()
      });
    },

    // 设置物料状态
    setMateriel(data) {
      if(data.isDisable == '启用'){
        this.cancelForm.state = 1
      }else{
        this.cancelForm.state = 0
      }
      this.cancelForm.specificationCode = data.specificationCode;
      this.cancelForm.type = 0
      this.saveOrderState()
    },

    saveReason(){
      this.$refs.cancelForm.validate((valid)=>{
        if(valid){
          this.saveOrderState()
        }
      })
    },


    // 保存编辑物料
    saveEditMater() {
      const parmas = this.materForm;
      this.$refs.materForm.validate((valid) => {
        if (valid) {
          this.addMaterrielLoading = true;
          this.$api.mater
            .UpdateGoods(parmas)
            .then(() => {
              this.isAddMaterriel = false;
              this.addMaterrielLoading = false;
              this.getAllMaterils();
              // 获取所有物料分组
              this.getMaterielClass();
              this.$message({
                message: "修改成功",
                type: "success",
              });
            })
            .catch(() => {
              this.addMaterrielLoading = false;
            });
        }
      });
    },
    // 规格删除
    specsDelete(index, data) {
      if (data.stockGoodsID) {
        const parmas = {
          entityID: data.stockGoodsID,
        };
        this.$api.mater.DeleteStockGoods(parmas).then((res) => {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          // this.getMaterielInfo(this.rowID)
          this.materForm.list.splice(index, 1);
        });
      } else {
        this.materForm.list.splice(index, 1);
      }
    },

    closeCancelDialog() {
      this.cancelForm = {
        specificationCode: "",
        type: 0,
        state: 0,
        reason: "",
      };
    },

    // 规格复制
    specsCopy(item) {
      const arr = {
        ...item,
      };
      arr.stockGoodsID = "";
      arr.goodsCode = " ";
      this.materForm.list.push(arr);
    },
    // 供应商
    getSupplier() {
      this.$api.mater.GetAllSuppliers().then((res) => {
        this.allSupliers = res;
      });
    },
    // 物料单位
    getMarCompany() {
      const parmas = {
        DictionaryCode: "GoodsUnit",
      };
      this.$api.mater.GetAllGoodsUnits(parmas).then((res) => {
        this.materielCompany = res;
        console.log(res)
        this.materForm.priceUnitCode = res[0].code;
      });
    },
    // 物料类型
    getMarTypes() {
      const parmas = {
        DictionaryCode: "GoodsCategory",
      };
      this.$api.mater.GetAllGoodsUnits(parmas).then((res) => {
        this.allMaterielTypes = res;
      });
    },
    // 物料详情
    getMaterielInfo(id) {
      const parmas = {
        queryBy: 1,
        queryValue: id,
      };
      this.$api.mater.GetSingleGoods(parmas).then((res) => {
        this.materForm = res;
        this.materForm.groupCode = this.materForm.goodsGroupCode;
        this.materForm.categoryCode = this.materForm.goodsTypeCode;
        this.materForm.stockGoodsName = this.materForm.specificationName;
        if (this.ops == "model") {
          this.materForm.stockGoodsName = "";
          this.materForm.specificationJsValue = "";
          this.materForm.specificationName = "";
          this.materForm.searchHotKeys = "";
          this.materForm.stockGoodsDesc = "";
        }
        // this.materForm.list = res.list;
      });
    },

    //保存订单状态
    saveOrderState() {
      this.$api.mater.UpdateGoodsSpecificationState(this.cancelForm).then((res) => {
        this.reasonVisible = false
        this.$message.success("保存成功");
        this.getAllMaterils();
      });
    },

    //查看
    seeMateriel(data) {
      this.ops = "see";
      // 物料详情
      this.getMaterielInfo(data.specificationCode);
      this.isDisable = true
      this.isAddMaterriel = true;
    },
    //修改
    modifyMateriel(data) {
      console.log(data)
      if(data.state == '已确认'){
        this.type = 'confirm'
      }else{
        this.type = ''
      }
      this.ops = "modify";
      this.isDisable = false
      // 物料详情
      this.getMaterielInfo(data.specificationCode);
      this.isAddMaterriel = true;
    },

    //添加规格型号
    handleAddModel(data) {
      this.ops = "model";
      this.type = ''
      // 物料详情
      this.isDisable = false
      this.getMaterielInfo(data.specificationCode);
      this.isAddMaterriel = true;
    },


    handleSearch() {
      this.search.pageIndex = 1;
      this.getAllMaterils();
    },

    // 删除物料分组
    deleteMaterielClass(data) {
      const parmas = {
        entityID: data.groupID,
      };
      this.$confirm("确定删除该分组, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.mater.DeleteGoodsGroup(parmas).then(() => {
          this.getMaterielClass();
          this.$message({
            message: "删除成功",
            type: "success",
          });
        });
      });
    },
    // 物料分组详情
    updateMaClass(data) {
      this.editMaterirlClass = true;
      this.materClassForm.groupName = data.groupName;
      this.materClassForm.groupID = data.groupID;
    },
    // 编辑物料分组
    saveEditMaterClass() {
      const parmas = this.materClassForm;
      this.$refs.editMaterClassForm.validate((valid) => {
        if (valid) {
          this.addMaterClassLoading = true;
          this.$api.mater
            .UpdateGoodsGroup(parmas)
            .then(() => {
              this.getMaterielClass();
              this.addMaterClassLoading = false;
              this.editMaterirlClass = false;
              this.$message({
                message: "编辑成功",
                type: "success",
              });
            })
            .catch(() => {
              this.addMaterClassLoading = false;
            });
        }
      });
    },
    // 新建物料分组
    saveMaterClass() {
      const parmas = this.materClassForm;
      this.$refs.materClassForm.validate((valid) => {
        if (valid) {
          this.addMaterClassLoading = true;
          this.$api.mater
            .AddGoodsGroup(parmas)
            .then(() => {
              this.getMaterielClass();
              this.addMaterirlClass = false;
              this.addMaterClassLoading = false;
              this.$message({
                message: "新建成功",
                type: "success",
              });
            })
            .catch(() => {
              this.addMaterClassLoading = false;
            });
        }
      });
    },
    // 物料分组改变事件
    changeMaterClass(item, index) {
      this.isAllMateriel = false;
      this.classIndex = index;
      this.search.groupCode = item.groupCode;
      this.backupsGroupCode = item.groupCode;
      this.subTitle = item.groupName;
      this.getAllMaterils();
    },
    // 全部物料
    getllMateriels() {
      this.isAllMateriel = true;
      this.materClassForm = this.$options.data().materClassForm;
      this.search.groupCode = "";
      this.backupsGroupCode = "";
      this.classIndex = null;
      this.subTitle = "全部物料";
      this.getAllMaterils();
    },
    // 全部物料，清除所有查询条件
    Refresh() {
      this.search = this.$options.data().search;
      this.getAllMaterils();
    },
    // 获取所有物料分组
    getMaterielClass() {
      this.$api.mater.GetAllGoodsGroupData().then((res) => {
        this.allMaterielClass = res;
      });
    },
    // 获取物料表格表头
    getTableHead() {
      const parmas = {
        tableCode: this.$config.goodslist,
      };
      this.$api.common.getAllTableHead(parmas).then((res) => {
        res.sort(arraySort("columnSort"));
        this.tableData.thead = res;
      });
    },

    //是否显示禁用
    handleIsShowDisabled(e) {
      console.log(e);
      if (e) {
        this.search.isShowDisabled = 1;
      } else {
        this.search.isShowDisabled = 0;
      }
      this.getAllMaterils();
    },

    // 所有物料列表数据
    getAllMaterils() {
      const parmas = this.search;
      this.searchLoading = true;
      this.$api.mater
        .GetMatchPageGoods(parmas)
        .then((res) => {
          res.list.forEach((item) => {
            if (item.state == 0) {
              item.state = "待确认";
            } else if (item.state == 1) {
              item.state = "已确认";
            } else {
              item.state = "已作废";
            }
            if (item.isDisable == 0) {
              item.isDisable = "启用";
            } else {
              item.isDisable = "禁用";
            }
          });
          this.tableData.tbody = res.list;
          this.search.total = res.totalCount;
          this.searchLoading = false;
        })
        .catch(() => {
          this.searchLoading = false;
        });
    },
    // 物料分组弹框关闭事件
    closeClassDialog() {
      // 关闭弹框的时候清空数据
      if (this.$refs.materClassForm) {
        this.$refs.materClassForm.resetFields();
      }
      if (this.$refs.editMaterClassForm) {
        this.$refs.editMaterClassForm.resetFields();
      }
      this.materClassForm = this.$options.data().materClassForm;
    },
    // 物料新建弹框关闭事件
    closeDialog() {
      if (this.$refs.materForm) {
        this.$refs.materForm.resetFields();
      }
      this.materForm = this.$options.data().materForm;
    },
    // 新建规格型号弹框关闭事件
    closeSpecsDialog() {
      if (this.$refs.specsForm) {
        this.$refs.specsForm.resetFields();
      }
      this.specsForm = this.$options.data().specsForm;
    },
  },
};
</script>
<style lang="scss" scoped>
.spot {
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 100%;
}

.addWuliaoBox {
  padding: 10px 16px;

  .tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;

    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
  }
}

.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}

.container {
  height: 100%;
}

.permangeRg {
  border: 1px solid #e6e6e6;
  background: #fff;
  margin-left: 18px;
  height: 100%;

  .mainTT {
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    padding: 18px 16px;
    padding-bottom: 0;
  }
}

.permanageLf {
  width: 280px;
  height: 100%;
  border: 1px solid #e6e6e6;
  background: #fff;

  .kuOP {
    display: none;
  }

  li {
    padding: 9px 16px;
    cursor: pointer;

    &:hover {
      background: #3f61f110;
      color: #3f61f1;

      .kuOP {
        display: block !important;
      }
    }
  }

  li.on {
    background: #3f61f110;
    color: #3f61f1;
  }

  .allMateriel {
    line-height: 44px;
    padding-left: 16px;

    &:hover {
      background: #3f61f110;
      color: #3f61f1;
    }
  }

  .allMateriel.crt {
    background: #3f61f110;
    color: #3f61f1;
  }
}

.navTT {
  line-height: 22px;
  padding: 16px;
}

.areasOp {
  li {
    padding: 8px 16px;
    cursor: pointer;

    &:hover {
      background: #f6f6f6;
    }
  }
}
</style>
